package com.chinasoft04.mall.mapper;

import com.chinasoft04.mall.dto.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Select("select * from sp_category where cat_level = #{type} and cat_pid = #{pid}")
    List<Category> selectAll(@Param("type") Integer type, @Param("pid") Integer pid);

    @Select("select count(*) from sp_category where cat_level = #{type} and cat_pid = #{pid}")
    int selectA(@Param("type") Integer type, @Param("pid") Integer pid);

    @Insert("insert into sp_category(cat_name, cat_pid, cat_level) values(#{cat_name}, #{cat_pid}, #{cat_level})")
    @Options(keyColumn = "cat_id",keyProperty = "cat_id",useGeneratedKeys = true)
    int insertOne(Category category);

    @Select("select * from sp_category where cat_id = #{id}")
    Category selectById(Integer id);

    @Update("update sp_category set cat_name = #{cat_name} where cat_id = #{id}")
    int updateById(@Param("id")Integer id, @Param("cat_name")String cat_name);

    @Delete("delete from sp_category where cat_id = #{id}")
    int deleteById(Integer id);
}
